package nl.ceasaro.jeslee.webapp.stock.action;

import com.opensymphony.xwork2.Action;
import org.apache.struts2.config.Namespace;
import org.apache.struts2.config.NullResult;
import org.apache.struts2.config.Result;
import org.apache.struts2.config.Results;
import org.springframework.stereotype.Component;
import nl.ceasaro.jeslee.core.stock.DressService;
import nl.ceasaro.jeslee.core.model.clothes.Dress;

import java.util.Collection;

import nl.ceasaro.jeslee.webapp.common.action.JesLeeAction;

import javax.annotation.Resource;

/**
 * Created by IntelliJ IDEA.
 * User: cees
 * Date: Oct 17, 2008
 * Time: 9:02:57 PM
 * <p>
 * This struts action class is responsible CRUD-actions on dresses.
 * </p>
 */
@Component
@Namespace(value = "/stock")
@Results({
    @Result(name=Action.SUCCESS, value="/stock/dress.jsp", type=NullResult.class),
    @Result(name= JesLeeAction.OVERVIEW, value="/stock/dresses.action", type=NullResult.class)
})

public class DressAction extends AbstractStockAction
{
   private Long id;
   private String name;
   private Dress dress;
   private static final long serialVersionUID = 1777128636351823195L;

   @Override
   public String execute() throws Exception
   {
      setDress(getDressService().getById(getId()));
      return SUCCESS;
   }

   public String storeDress() throws Exception
   {
      getDressService().save(getDress());
      return OVERVIEW;
   }

   public Long getId()
   {
      return id;
   }

   public void setId(Long id)
   {
      this.id = id;
   }

   public String getName()
   {
      return name;
   }

   public void setName(String name)
   {
      this.name = name;
   }

   public Dress getDress()
   {
      return dress;
   }

   public void setDress(Dress dress)
   {
      this.dress = dress;
   }

   /*
   * ******************************************
   * Spring injections
   * ******************************************
   */
   private DressService dressService;

   public DressService getDressService()
   {
      return dressService;
   }

   @Resource
   public void setDressService(DressService dressService)
   {
      this.dressService = dressService;
   }
}